module.exports = function(grunt) {
    var devSrc = 'dev/',
        masterSrc = 'master/',
        allFile = '**/*',
        copySrc = [
            allFile + '{.php,.gif,.jpeg,.tpl}',
        ],
        ugilfySrc = allFile + '.js',
        imageminSrc = allFile + '.*',
        cssminSrc = allFile + '.css',
        htmlminSrc = allFile + '.html';

    // 任务配置
    grunt.initConfig({
        // pkg: grunt.file.readJSON('src.json'),
        concat: {
            options: {
              separator: '\n',
              banner: '/*编译时间：<%= grunt.template.today("yyyy-mm-dd") %> */',
            },
            dist: {
              src: ['dev/component/seajs/2.3.0/sea.js','dev/component/seajs/2.3.0/seajs-text.js','dev/component/seajs/2.3.0/seajs-css.js','dev/component/seajs/2.3.0/seajs-preload.js'],
              dest: 'dev/component/seajs/2.3.0/seajs.js',
            },
        },

        copy: {
            main: {
                files: [{
                    expand: true,
                    cwd: devSrc,
                    src: copySrc,
                    dest: masterSrc,
                }]
            },
        },
        htmlmin: {
            dist: {
                options: {
                    minifyCSS: true,
                    minifyJS: true,
                    removeComments: true,
                    collapseWhitespace: true
                },
                files: [{
                    expand: true,
                    cwd: devSrc,
                    src: htmlminSrc,
                    dest: masterSrc,
                }]
            }
        },

        // Task jsmin
        uglify: {
            options: {
                // banner: '<%= window.lang.foo %>',
                mangle: false
            },
            build: {
                files: [{
                    expand: true,
                    cwd: devSrc, //js目录下
                    src: ugilfySrc,
                    dest: masterSrc,
                }]
            }
        },

        // Task cssmin
        cssmin: {
            with_banner: {
                files: [{
                    expand: true,
                    cwd: devSrc,
                    src: cssminSrc,
                    dest: masterSrc,
                }]
            }
        },

        imagemin: {
            dist: { // Target
                options: { // Target options
                    optimizationLevel: 3
                },
                files: [{
                    expand: true,
                    cwd: devSrc,
                    src: imageminSrc,
                    dest: masterSrc,
                }]
            }
        },

        shell: {
            options: {
                stderr: false,
                // execOptions: {
                //     maxBuffer: 2000 * 1024
                // },
            },
            remove: {
                command: 'rm -rf master'
            }
        },

    });

    // 配置任务

    // Load the plugin HTML/CSS/JS/IMG min
    grunt.loadNpmTasks('grunt-shell');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-imagemin');

    // Build task(s).
    grunt.registerTask('build', ['shell','concat','htmlmin', 'uglify', 'cssmin', 'imagemin', 'copy']);
    // grunt.registerTask('build', ['shell']);
};
